import { FC, PropsWithChildren, useMemo } from 'react';
import { usePermissions } from '@/store/userStore.ts';

type Props = {
  permissions: string[];
};

const PermissionGuard: FC<PropsWithChildren<Props>> = ({ permissions, children }) => {
  const _permissions = usePermissions();
  const show = useMemo(() => {
    return permissions.every((p) => _permissions.includes(p));
  }, [_permissions, permissions]);

  return <>{show ? children : null}</>;
};

export default PermissionGuard;
